import {
    _decorator,
    Asset,
    Component,
    ImageAsset,
    Node,
    Sprite,
    SpriteFrame,
} from 'cc';
import { resMgr } from 'db://assets/component/res-load/ResMgr';
const { ccclass, property } = _decorator;

@ccclass('ResourceTest')
export class ResourceTest extends Component {
    @property([Sprite])
    sp1: Sprite[] = [];

    start() {}

    fn1() {
        resMgr.loadRes('1').then((value: Asset) => {
            console.log(value);
            const imageAsset = value as ImageAsset;
            let spriteFrame = SpriteFrame.createWithImage(imageAsset);
            this.sp1[0].spriteFrame = spriteFrame;
        });
    }

    fn2() {
        resMgr.loadRes('1/spriteFrame').then((value: Asset) => {
            console.log(value);

            let spriteFrame = value as SpriteFrame;
            this.sp1[1].spriteFrame = spriteFrame;
        });
    }
    fn3() {
        resMgr.loadRes('1').then((value: Asset) => {
            console.log(value);
            const imageAsset = value as ImageAsset;
            let spriteFrame = SpriteFrame.createWithImage(imageAsset);
            this.sp1[2].spriteFrame = spriteFrame;
        });
    }

    fn4() {
        resMgr.loadRes('1').then((value: Asset) => {
            console.log(value);
            const imageAsset = value as ImageAsset;
            let spriteFrame = SpriteFrame.createWithImage(imageAsset);
            this.sp1[3].spriteFrame = spriteFrame;
        });
    }

    release() {
        resMgr.releaseFile('1');
        resMgr.releaseFile('1/spriteFrame');
    }

    update(deltaTime: number) {}
}
